home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / turbcomm.arc / GETENV.INC < prev    next >
Text File  |  1989-06-30  |  2KB  |  53 lines

  1. { File: GETENV2.INC }
  2. {
  3. ** The following function will look for an environment variable
  4. ** and return it's definition if found.  If the variable is not
  5. ** found, then the returned definition variable will be empty.
  6. ** Compiled and run with Turbo Pascal v2.0 on an IBM PC/XT running
  7. ** PC-DOS v2.1.
  8. **
  9. ** This code is entered into the Public Domain for free use by all.
  10. ** George B. Smith, March 15, 1985. }
  11.  
  12.    type Env_String = string[80];
  13.  
  14. procedure GetEnvParam(name: Env_String;  { environment variable to search for }
  15.                       var param: Env_String  { returned definition }
  16.                      );
  17.  
  18. var
  19.     envseg: integer;     { segment address of environment from PSP }
  20.     ei: integer;         { index into environment }
  21.     envname: Env_String;    { current environment string name }
  22.     ch: char;            { current character from environment }
  23.     found: boolean;      { if true then environment name was found }
  24.  
  25. begin
  26.     envseg := MemW[CSeg:$2C];        { get address of environment from PSP }
  27.     found := FALSE;
  28.     ch := chr(Mem[envseg:ei]);       { get first char from environment }
  29.     while (ch <> chr(0)) and (not found) do begin
  30.         envname := '';
  31.         while (ch <> '=') AND (Length(EnvName) < 255)
  32.            do begin     { get environment string name }
  33.             envname := envname + ch;
  34.             ei := ei + 1;
  35.             ch := chr(Mem[envseg:ei])
  36.         end;
  37.         ei := ei + 1;                { skip over the EQUALS }
  38.         param := '';
  39.         ch := chr(Mem[envseg:ei]);
  40.         while ch <> chr(0) do begin  { get environment string parameter }
  41.             param := param + ch;
  42.             ei := ei + 1;
  43.             ch := chr(Mem[envseg:ei])
  44.         end;
  45.         if name = envname then       { check for a match }
  46.             found := TRUE;
  47.         ei := ei + 1;
  48.         ch := chr(Mem[envseg:ei])
  49.     end;
  50.     if not found then
  51.         param := ''
  52. end; { Procedure GetEnvParam }
  53.